package tenantchannellogic

import (
	"context"
	model "gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/dao/model/tenant/channel"
	schema "gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/dao/schema/tenant/channel"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/pkg/xerrors"

	"gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/rpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UsdtCreateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUsdtCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UsdtCreateLogic {
	return &UsdtCreateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// UsdtCreate usdt
func (l *UsdtCreateLogic) UsdtCreate(in *rpc.UsdtCreateRequest) (*rpc.UsdtCreateResponse, error) {
	var CommonResp rpc.CommonResp
	usdt := &schema.TenantChannelUsdt{
		Name:     in.Name,
		UsdtType: in.UsdtType,
		QrCode:   in.QrCode,
		Address:  in.Address,
		Sort:     in.Sort,
	}
	err := model.NewTenantChannelUsdtModel(l.ctx, l.svcCtx.Db).CreateUsdt(usdt)
	if err != nil {
		CommonResp.Code = xerrors.DBError
		CommonResp.Message = "Database operation error"
		return &rpc.UsdtCreateResponse{
			CommonResp: &CommonResp,
		}, err
	}
	CommonResp.Message = "Success"
	return &rpc.UsdtCreateResponse{
		CommonResp: &CommonResp,
	}, nil
}
